<template>
	<view class="container">
		<Comment :list="commentList"></Comment>
		<!-- 内容为空 -->
		<u-empty mode="list" text="暂无评论" margin-top="240" v-show="(this.commentList.length == 0)"></u-empty>
        <!-- 提示栏 -->
        <u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {  getsceniccomments } from '../../api/scenic.js'
	import Comment from '../../components/comments.vue'
	export default {
		data() {
			return {
				total: '',
				params: {
				 scenicId: '',
				 pageNum: 1,
				 pageSize: 9
				},
				commentList: []
			}
		},
		components:{
			Comment
		},
		onLoad(e) {
			this.params.scenicId = e.id
		  uni.setNavigationBarTitle({
		  	title: '评论列表'
		  })	
		},
		mounted() {
		  this.getCommentList()
		},
		onReachBottom() {
			if (this.total >= (this.params.pageNum *this.params.pageSize)) {
				 this.getMore()
			} else {
				this.$refs.uToast.show({
					title: '没有数据了',
					position: 'top'
					})
			}
		},
		methods: {
		  // 获取评论列表
		  async getCommentList () {
			const res = await getsceniccomments(this.params)
			this.commentList = res.data.data.data
			this.total = res.data.data.total
		  },
		  // 加载下一页数据
		  async getMore () {
			  this.params.pageNum ++
			  const params = this.params
			  const res = await getsceniccomments(this.params)
			  this.commentList = [...this.commentList, ...res.data.data.data] 
		  }
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background-color: #fff;
		padding: 24rpx;
	}
</style>
